let inputSearch01 = document.getElementById("inputSearch01");
let val = null,
	ele01 = null;
let bodyEle = document.body;
let searchUl = document.getElementsByClassName("searchUl")[0];

function makeLiSuggestion(data) {
	if(data) {
		let objs = data.s;
		searchUl.innerHTML = "";
		searchUl.style.display = "block";
		for(let i = 0; i < objs.length; i++) {
			let lis01 = document.createElement("li");
			let aLinks01 = document.createElement("a");
			aLinks01.target = "_blank";
			aLinks01.innerHTML = objs[i];
			aLinks01.href = "http://www.baidu.com/s?wd=" + objs[i];
			lis01.appendChild(aLinks01);
			searchUl.appendChild(lis01);
			//console.log(aLinks01.href);
		}

		return;
	}

}
let fun01 = function() {
	val = inputSearch01.value;
	searchUl.style.display = "block";
	if(val.trim() !== "") {
		// 上面已经判断好有输入内容，可以进行请求给出建议搜索条目
		bodyEle.removeChild(document.getElementsByClassName("scri")[0]);

		let script01 = document.createElement("script");
		script01.classList.add("scri");
		//script01.src = "http://suggestion.baidu.com/su?wd=" + val + "&cb=" + makeLiSuggestion;
		script01.src = `https://suggestion.baidu.com/su?wd=${val}&&cb=makeLiSuggestion`;
		bodyEle.appendChild(script01);

		//return;
	} else {
		searchUl.innerHTML = "";
		ele01 = document.createElement("li");
		ele01.innerHTML = "请输入搜索内容！";
		ele01.style.color = "red";
		ele01.style.background = "rgba(120, 20, 220, 0.9)";
		searchUl.appendChild(ele01);
	}
}
inputSearch01.addEventListener("keyup", fun01);
inputSearch01.nextElementSibling.onclick = fun01();
document.addEventListener("click", function(e) {
	let ee = e || window.event;
	if(ee) {
		if(ee.target.id && ee.target.id === "searchDiv01") {

			return;
		}
		searchUl.innerHTML = ""; // 鼠标离开输入框，建议提示被清空且隐藏起来
		searchUl.style.display = "none";
		//console.log(ee.target.id);
	}
});

//});